package com.egreen.asset.controller;


import com.egreen.asset.service.IBalanceAccountService;
import com.egreen.asset.service.IOperateBalanceRecordingService;
import com.egreen.common.Result;
import com.egreen.common.pojo.DTO.asset.BalanceAccountDTO;
import com.egreen.common.serviceapi.user.IUserServiceApi;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cloudJiang
 * @since 2022-07-16
 */
@Log
@RestController
@RequestMapping("/tdBalanceAccount")
public class BalanceAccountController {
    @Autowired
    IBalanceAccountService balanceAccountService;
    @Autowired
    IOperateBalanceRecordingService balanceRecordingService;
    @DubboReference
    IUserServiceApi userServiceApi;

    /**
     * 创建用户余额账户(需要前端提供支付宝的信息)
     *
     * @param balanceAccountDTO
     */
    @ApiOperation(value = "创建余额账户", notes = "通过调用addBalanceAccount方法，创建余额账户")
    @PostMapping("/addBalanceAccount")
    public Result addBalanceAccount(@RequestBody BalanceAccountDTO balanceAccountDTO) {
        int i = balanceAccountService.addBalanceAccount(balanceAccountDTO);
        return Result.OK(i);
    }

    @ApiOperation(value = "获取余额账户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true)
    })
    @GetMapping("/getBalanceMessage")
    public Result getBalanceMessage(@RequestParam("id") Long id) {
        return Result.OK(balanceRecordingService.selectBalanceAccountById(userServiceApi.selectUserById(id).getBalanceAccountId()));
    }

    @ApiOperation(value = "获取用户余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true)
    })
    @GetMapping("/getUserBalance")
    public Result getUserBalance(@RequestParam("id") Long id) {
        return Result.OK(balanceAccountService.selectBalanceByUserId(id));
    }

}

